public class CXGAccountUpdateOperation
{
	public static void CustomerRetentionAccountUpdate(List<Customer_Retention__c> custRetnList)
	{
		Set<Id> accountIds = new Set<Id>();
		for (Customer_Retention__c cr : custRetnList)
		{
			if (cr.Related_Account__c != null)
				accountIds.add(cr.Related_Account__c);
		}			
		System.debug('accountIds=' + accountIds);
				        
        // Query a list of existing Customer Retention records for associated Accounts, ordering
        // by Date__c because we always want the most recent one for each Account on top.
        Set<Id> tempAccountIds = new Set<Id>();
		List<Account> accountsList = new List<Account>();
		for (Customer_Retention__c cr: [
			select Id, Status__c, Date__c, Related_Account__c 
			from Customer_Retention__c 
			where Related_Account__c = :accountIds 
			order by Date__c desc])
		{
			if (!tempAccountIds.contains(cr.Related_Account__c))
			{
				// Add the Id to the set so we ignore older customer retention records for this account.
				tempAccountIds.add(cr.Related_Account__c);
										
				Account acct = new Account(
					Id = cr.Related_Account__c,
					Churn_Status__c = cr.Status__c,
					Month_Year__c = cr.Date__c);
				accountsList.add(acct);
			}
		}
		
		// Save the account updates
		System.debug('accountsList=' + accountsList);	
		update accountsList;
	}
}